package univ.paris.ouest.service;



import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;

import univ.paris.ouest.data.IUserLoginDao;
import univ.paris.ouest.domaine.UserLogin;

public class UserLoginManager implements IUserLogin{

	@Autowired
	private IUserLoginDao userLoginDaoHib;
	@Autowired
	private SessionFactory sessionFactory;
	private Transaction tx;
	private Session session;
	
	@Override
	public void creatUserLogin(UserLogin userLogin ) {
		this.userLoginDaoHib.saveUserLogin(userLogin);
	}
	@Override
	public void upDateUserLogin(UserLogin userLogin) {
		this.userLoginDaoHib.upDateUserLogin(userLogin);
	}
	@Override
	public UserLogin getUserLogin(UserLogin userLogin) {
		this.session=this.sessionFactory.openSession();
	    this.tx=this.session.beginTransaction();
	    this.userLoginDaoHib.setSession(session);
	    userLogin=this.userLoginDaoHib.getUserLogin(userLogin);
	    this.tx.commit();this.session.close();
		return userLogin;
	}

}
